import allure
from playwright.sync_api import Page

class AddProjectPage:
    def __init__(self, page:Page):
        self.page = page
        self.locator_project_name = self.page.get_by_label("项目名称:")
        self.locator_project_app = self.page.get_by_label("所属应用:")
        self.locator_project_desc = self.page.get_by_label("项目描述:")
        self.locator_save_btn = self.page.get_by_text("点击提交")

    def navigate(self):
        with allure.step("导航到添加项目页面"):
            self.page.goto("/add_project.html")

    def fill_project_name(self, name:str):
        with allure.step("输入项目名称"):
            self.locator_project_name.fill(name)

    def fill_project_app(self, app_name:str):
        with allure.step("输入所属应用"):
            self.locator_project_app.fill(app_name)

    def fill_project_desc(self, desc:str):
        with allure.step("输入项目描述"):
            self.locator_project_desc.fill(desc)

    def click_save_btn(self):
        with allure.step("点击添加按钮"):
            self.locator_save_btn.click()

    def save_project(self,name,app_name,desc):
        self.fill_project_name(name)
        self.fill_project_app(app_name)
        self.fill_project_desc(desc)
        self.click_save_btn()